package ua.tach.shortl.logic;

import ua.tach.shortl.Renderer;

import com.badlogic.gdx.math.Vector3;

public class SwitchPlace {
	public static final int SHIFTX = 80;
	public static final int SHIFTY = 0;
	public static final int MULX = 800-80;
	public static final int MULY = 480-48;
	public static final float HEIGHT = 0.1f;

	public Switch sw;
	public Vector3 scr;
	private float x = 0;
	private float y = 0;

	public	SwitchPlace ( Switch s) {
		sw = s;
		getShift(s.getSemType(), s.linkDir);
		scr = new Vector3(s.getParent().index.x+x, HEIGHT, s.getParent().index.y+y);
		calcPlace();
	}

	private void calcPlace() {
		scr.prj(Renderer.camera.combined);
		scr.x = SHIFTX + MULX*(scr.x+1)/2;
		scr.y = SHIFTY + MULY* (1-scr.y)/2;
		System.out.println ("Scr coordinates "+scr+ " real "+sw.getParent().index);
	}

	private void getShift (int type, int dir) {
		x = 0;
		y = 0;
		switch (dir) {
		case 0:
			if (type==2)
				y = 0.3f;
			else
				x = 0.25f;
			break;
		case 1:
			if (type==2)
				x = -0.3f;
			else
				y = 0.25f;
			break;
		case 2:
			if (type==2)
				y = -0.3f;
			else
				x = -0.25f;
			break;
		default:
			if (type==2)
				x = 0.3f;
			else
				y = -0.25f;
		}
		System.out.println("Dir: "+ dir+ " type: "+type+ " shift x: " + x + " y: " + y);
	}

	public void change() {
		getShift(sw.getSemType(), sw.linkDir);
		scr.set(sw.getParent().index.x+x, HEIGHT, sw.getParent().index.y+y);
		calcPlace();
	}
}
